package com.vcit.term.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.vcit.common.utils.poi.ExcelUtil;
import com.vcit.system.domain.term.Term;

import com.vcit.system.service.term.TermService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.vcit.common.annotation.Log;
import com.vcit.common.core.controller.BaseController;
import com.vcit.common.core.domain.AjaxResult;
import com.vcit.common.enums.BusinessType;
import com.vcit.common.core.page.TableDataInfo;

/**
 * 学期Controller
 * 
 * @author dff
 * @date 2025-01-07
 */
@Api("学期信息管理")
@RestController
@RequestMapping("/system/term")
public class TermController extends BaseController
{
    @Autowired
    private TermService termService;

    /**
     * 查询学期列表
     */
    @ApiOperation("获取学期信息列表")
    @PreAuthorize("@ss.hasPermi('system:term:list')")
    @GetMapping("/list")
    public TableDataInfo list(Term term)
    {
        startPage();
        List<Term> list = termService.selectTermList(term);
        return getDataTable(list);
    }
    @ApiOperation("获取学期信息下拉列表")
    @GetMapping("/selectList")
    public List<Term> selectList(Term term)
    {

        List<Term> termList = termService.selectTermList(term);
        return termList;
    }

    /**
     * 导出学期列表
     */
    @ApiOperation("导出学期信息列表")
    @PreAuthorize("@ss.hasPermi('system:term:export')")
    @Log(title = "学期", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Term term)
    {
        List<Term> list = termService.selectTermList(term);
        ExcelUtil<Term> util = new ExcelUtil<Term>(Term.class);
        util.exportExcel(response, list, "学期数据");
    }

    /**
     * 获取学期详细信息
     */
    @ApiOperation("获取学期详细信息列表")
    @PreAuthorize("@ss.hasPermi('system:term:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(termService.selectTermById(id));
    }

    /**
     * 新增学期
     */
    @ApiOperation("新增学期信息列表")
    @PreAuthorize("@ss.hasPermi('system:term:add')")
    @Log(title = "学期", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Term term)
    {
        return toAjax(termService.insertTerm(term));
    }

    /**
     * 修改学期
     */
    @ApiOperation("修改学期信息列表")
    @PreAuthorize("@ss.hasPermi('system:term:edit')")
    @Log(title = "学期", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Term term)
    {
        return toAjax(termService.updateTerm(term));
    }

    /**
     * 删除学期
     */
    @ApiOperation("删除学期信息")
    @PreAuthorize("@ss.hasPermi('system:term:remove')")
    @Log(title = "学期", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(termService.deleteTermByIds(ids));
    }
}
